package StudyCode.summary.BufferAndChannel;

import java.nio.CharBuffer;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class DemonstrateBehaviorCharSequence {
	public static void main(String[] argv) {
		StringBuffer stringBuffer = new StringBuffer("Hello World");
		CharBuffer charBuffer = CharBuffer.allocate(20);
		CharSequence charSequence = "Hello World";
		printCharSequence(charSequence);
		charSequence = stringBuffer;
		printCharSequence(charSequence);
		stringBuffer.setLength(0);
		stringBuffer.append("hi");
		printCharSequence(charSequence);
		charSequence = charBuffer;
		charBuffer.put("test");
		charBuffer.clear();
		charBuffer.put("Hello World");
		charBuffer.flip();
		printCharSequence(charSequence);
		charBuffer.mark();
		charBuffer.put("tah1986");
		charBuffer.reset();
		printCharSequence(charSequence);
		charBuffer.clear();
		printCharSequence(charSequence);
	}

	private static void printCharSequence(CharSequence cs) {
		System.out.println("length=" + cs.length() + ", content='" + cs.toString()
				+ "'");
	}
}
